package com.zl.smartmall.library.listener;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zl.smartmall.library.po.GZCommunity;
import com.zl.smartmall.library.po.GZCommunityInfo;
import com.zl.smartmall.library.util.Constants;
import com.zl.smartmall.library.util.PreferenceModel;

public abstract class SelectDefaultCommunityListener extends BaseListener {
	private int cmid;
	
	public int getCmid() {
		return cmid;
	}
	public void setCmid(int cmid) {
		this.cmid = cmid;
	}
	public abstract void onResponseSuccess();
	@Override
	public void onNoMoreData() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
		try {
			int ret = response.getInt("ret");
			switch (ret) {
			case 0:
				PreferenceModel.putInt(Constants.PREFERENCE_KEY_COMMUNITY_ID, cmid);
				onResponseSuccess();
				break;
			case 2:
				onOffline();
				break;
				
			default:
				onResponseFailed();
				break;
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			onResponseFailed();
		}
	}
	
	@Override
	public void onFailure(int statusCode, Header[] headers,
			String responseString, Throwable throwable) {
		super.onFailure(statusCode, headers, responseString, throwable);
		onResponseFailed();
	}
}
